﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Text;

using CE.Mail;
using CE.User;
using CE.Database;
using CE.TravelInsurance;
using CE.Global;
using CE.Provider;
using CE.AreaCountry;

public partial class travel_travel_result : System.Web.UI.Page
{
    private Int32 RowCount = 0;
    private string TripType = "S";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.IsSecureConnection)
            {
                string redirectUrl = Request.Url.ToString().Replace("https:", "http:");
                Response.Redirect(redirectUrl);
            }

            if (Request.UrlReferrer == null)
            {
                Response.Redirect("travel-quote.aspx");
            }

            //if (Session[General.TAId] != null)
            //{
            //    inputPlanType.Value = Session["PlanType"].ToString();
            //    LoadSummary();
            //}

            Session[General.TAResultId] = null;
            ResultsQuotesDataBind();
            Session[General.ViewedDetailsId] = LogUserViewedHistory().ToString();

        }
    }

    private void ResultsQuotesDataBind()
    {
        if (Session[General.TAId] == null)
        {
            Response.Redirect("travel-quote.aspx");

        }

        //Sakthi on 30 Dec 2010 -- End
        if (Cache["Mobile.TAResultsQuotes" + Session[General.TAId].ToString()] == null)
            GetTempResultTable();

        DataView dv = new DataView((DataTable)Cache["Mobile.TAResultsQuotes" + Session[General.TAId].ToString()]);

        dlTravelResults.DataSource = (DataTable)Cache["Mobile.TAResultsQuotes" + Session[General.TAId].ToString()];
        dlTravelResults.DataBind();

    }

    private Int64 LogUserViewedHistory()
    {
        UserViewHistoryDB _userviewdb = new UserViewHistoryDB();
        //Sakthi on 15 Feb 2011 Command
        //return _userviewdb.LogViewedHistory("TA", Request, "Travel Insurance results quotes one.");
        return _userviewdb.LogResultViewedHistory("TA", Request, "Travel Insurance results quotes one.");
    }

    private void GetTempResultTable()
    {
        string CoverType = "";
        Int32 Duration = 0;
        string CoverageLevel = "";
        string Trip = "";
        Int64 AreaId = 0;
        Int64 CountryId = 0;
        Int32 AdultAge = 0;
        Int32 ChildAge = 0;
        Int64 TAId = 0;
        Int32 NoOfAdults = 0;
        Int32 NoOfChilds = 0;

        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

        if (Session[General.TAId] != null && Session[General.TAId].ToString() != "")
            TAId = Convert.ToInt64(Session[General.TAId].ToString());
        else
        {
            Response.Redirect("travel-quote.aspx");
        }

        _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

        if (_taapplicantsearch != null)
        {
            //Response.Write("<script>window.alert('ok ')</script>");
            CoverType = _taapplicantsearch.PlanType;
            Duration = _taapplicantsearch.Duration;
            AreaId = _taapplicantsearch.AreaID;
            CountryId = _taapplicantsearch.CountryID;
            AdultAge = _taapplicantsearch.AdultAge;
            ChildAge = _taapplicantsearch.ChildAge;
            CoverageLevel = _taapplicantsearch.CoverageLevel;
            Trip = _taapplicantsearch.TripType;
            NoOfAdults = _taapplicantsearch.NoofAdults;
            NoOfChilds = _taapplicantsearch.NoofChilds;
            MyDatabase _db = new MyDatabase();
            DataTable _dtResult = new DataTable();

            TAQuoteResultDB _taquoteresultdb = new TAQuoteResultDB();

            if (_taapplicantsearch.Ninfo3 != 0)
            {
                //with Promo per Provider
                _dtResult = _taquoteresultdb.GetTAQuoteResultDisplayByProviderWithPromo(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, _taapplicantsearch.Ninfo3, NoOfAdults, NoOfChilds, TAId);
            }
            else
            {
                _dtResult = _taquoteresultdb.GetTAQuoteResultDisplay(GetCovertype(CoverType), Duration.ToString(), AreaId, CountryId, AdultAge, ChildAge, CoverageLevel, Trip, NoOfAdults, NoOfChilds, TAId);
            }

            RowCount = _dtResult.Rows.Count;

            DataView dv = new DataView(_dtResult);
            string strSortExpress = "AnnualPremium ASC";
            dv.Sort = strSortExpress;
            Cache["Mobile.TAResultsQuotes" + Session[General.TAId].ToString()] = dv.ToTable();
        }
        else
        {
            Response.Redirect("travel-quote.aspx");
        }

    }

    protected void dlTravelResults_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item ||
             e.Item.ItemType == ListItemType.AlternatingItem)
        {
            ImageButton imgEmailQuote = (ImageButton)e.Item.FindControl("imgEmailQuote");
            imgEmailQuote.Attributes.Add("onclick", "return confirm('Are you sure you want to send this quote?');");

            Label lblPremiumAmount = (Label)e.Item.FindControl("lblPremiumAmount");
            Label lblPromotionPrice = (Label)e.Item.FindControl("lblPromotionPrice");

            Label lblProviderCompanyName = (Label)e.Item.FindControl("lblProviderCompanyName");

            Label lblPlanName = (Label)e.Item.FindControl("lblPlanName");
            Label lblProviderCompanyID = (Label)e.Item.FindControl("lblProviderCompanyID");
            Label lblTAResultID = (Label)e.Item.FindControl("lblTAResultID");
            Image imgProviderCompanyLogo = (Image)e.Item.FindControl("imgProviderCompanyLogo");

            string _premiumAmount = DataBinder.Eval(e.Item.DataItem, "AnnualPremium").ToString().Trim();
            lblPremiumAmount.Text = "S$ " + Convert.ToSingle(_premiumAmount).ToString("#,00.00");

            lblProviderCompanyID.Text = DataBinder.Eval(e.Item.DataItem, "ProviderCompanyId").ToString();
            lblProviderCompanyName.Text = DataBinder.Eval(e.Item.DataItem, "InsurerName").ToString();
            lblPlanName.Text = DataBinder.Eval(e.Item.DataItem, "PlanName").ToString();
            lblTAResultID.Text = DataBinder.Eval(e.Item.DataItem, "TAInsID").ToString();

            HyperLink hlnkView = (HyperLink)e.Item.FindControl("hlnkView");
            hlnkView.NavigateUrl = "travel-result-detail.aspx?taid=" + lblTAResultID.Text;

            HyperLink hlnkViewTop = (HyperLink)e.Item.FindControl("hlnkViewTop");
            hlnkViewTop.NavigateUrl = "travel-result-detail.aspx?taid=" + lblTAResultID.Text;

            string companylogourl = DataBinder.Eval(e.Item.DataItem, "CompanyLogoServerUrl").ToString();

            if (DataBinder.Eval(e.Item.DataItem, "CompanyLogoServerUrl").ToString().Length > 0)
            {
                if (DataBinder.Eval(e.Item.DataItem, "CompanyLogoServerUrl").ToString().Substring(0, 1) == "~")
                {
                    companylogourl = DataBinder.Eval(e.Item.DataItem, "CompanyLogoServerUrl").ToString().Remove(0, 1);
                }
            }

            imgProviderCompanyLogo.ImageUrl = "http://www.comparexpress.com" + companylogourl;

            string _providercompanyid = DataBinder.Eval(e.Item.DataItem, "providercompanyid").ToString();
            string _planname = DataBinder.Eval(e.Item.DataItem, "planname").ToString();
            Int64 _resultId = Convert.ToInt64(DataBinder.Eval(e.Item.DataItem, "TAInsID").ToString());
            Int64 _taid = Convert.ToInt64(Session[General.TAId].ToString());
            Int64 _userId = 0;
            
            if (Session[General.UserId] != null)
                _userId = Convert.ToInt64(Session[General.UserId].ToString());
            else if (Session[General.TAPersonnelId] != null)
                _userId = Convert.ToInt64(Session[General.TAPersonnelId].ToString());

            string _fullname = "";
            string _mobile = "";
            string _email = "";
            string _nric = "";
            string _title = "";
            string _ctname2 = "";
            
            if (Session[General.TAUserName] != null)
                _fullname = Session[General.TAUserName].ToString();

            if (Session[General.TAPhoneNo] != null)
                _mobile = Session[General.TAPhoneNo].ToString();

            if (Session[General.TAEmail] != null)
                _email = Session[General.TAEmail].ToString();

            if (Session["Mobile.NRIC"] != null)
                _nric = Session["Mobile.NRIC"].ToString();

            if (Session["Mobile.SpouseName"] != null)
                _ctname2 = Session["Mobile.SpouseName"].ToString();

            
            ImageButton ibtBuyNow = (ImageButton)e.Item.FindControl("ibtBuyNow");

            //ibtBuyNow.Click += new ImageClickEventHandler(this.ibtBuyNow_Click);

            ibtBuyNow.OnClientClick = "javascript:void(0);ManageRedirect('" + _providercompanyid + "', '" + _resultId + "', " +
                        "'" + _premiumAmount + "', '" + _userId + "','" + _taid + "', '" + _planname + "', '" + _fullname + "', " +
                        "'" + _mobile + "', '" + _email + "', '" + _nric + "', '" + _title + "', '" + _ctname2 + "');return false;";
            
        }
    }

    protected void dlTravelResults_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "Email")
        {
            Label lblTAResultID = (Label)e.Item.FindControl("lblTAResultID");

            this.EmailQuote(lblTAResultID.Text);
        }

        if (e.CommandName == "ViewDetails")
        {
            //e.Item.DataItem
            Label lblTAResultID = (Label)e.Item.FindControl("lblTAResultID");

            if (lblTAResultID.Text.Trim() != "")
            {
                //Session["CarSelected"] = lblTAResultID.Text;
                Response.Redirect("travel-result-detail.aspx?taid=" + lblTAResultID.Text);
            }
        }

        //if (e.CommandName == "BuyNow")
        //{
        //    this.BuyNow();
        //}
    }

    private string GetCovertype(string covertype)
    {
        string coverparam = "";
        if (covertype == "IND")
            coverparam = "Individual";
        else if (covertype == "INS")
            coverparam = "IndividualSpouse";
        else if (covertype == "FML")
            coverparam = "Family";
        else if (covertype == "INC")
            coverparam = "IndividualChild";

        return coverparam;
    }

    private void EmailQuote(string taresultid)
    {
        string qs_tiselected = taresultid;
        string _triptype = "";
        string _policy = "";
        string _traveldate = "";
        string _travellers = "";
        string _destination = "";
        string _coverage = "";
        string _quotedate = "";
        string _providercompanyid = "";

        Int64 _cecarid = 0;

        if (Session[General.TAId] != null && Session[General.TAEmail] != null)
        {
            Int64 TAId = 0;

            TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
            TAApplicantSearch _taapplicantsearch = new TAApplicantSearch();

            if (Session[General.TAId] != null)
                TAId = Convert.ToInt64(Session[General.TAId]);

            _taapplicantsearch = _taapplicantsearchdb.GetTAApplicantSearchItem(TAId);

            if (_taapplicantsearch != null)
            {
                _triptype = GetCoverage(_taapplicantsearch.TripType.ToString());
                _policy = GetPolicy(_taapplicantsearch.PlanType.ToString());
                _traveldate = String.Format("{0:dd/MM/yyyy} To {1:dd/MM/yyyy}", _taapplicantsearch.StartDate, _taapplicantsearch.EndDate);
                _travellers = (_taapplicantsearch.NoofChilds + _taapplicantsearch.NoofAdults).ToString();

                if (_taapplicantsearch.AreaID != 0)
                    _destination = GetAreaName(_taapplicantsearch.AreaID);
                else
                    _destination = GetCountryName(_taapplicantsearch.CountryID);

                _coverage = GetCoverage(_taapplicantsearch.CoverageLevel);
                _quotedate = CE.Global.General.GetUTCDateTime().ToString("dd/MMM/yyyy");
            }

            string _refno = "";
            string _companyName = "";
            string _insurerimageurl = "";
            string _package = "";
            string _annualprice = "";

            string _paadult = ""; bool _paadultNo = false;
            string _pasenior = ""; bool _paseniorNo = false;
            string _diadult = ""; bool _diadultNo = false;
            string _disenior = ""; bool _diseniorNo = false;
            string _medexpadult = ""; bool _medexpadultNo = false;
            string _medexpsenior = ""; bool _medexpseniorNo = false;
            string _emergencymedevac = ""; bool _emergencymedevacNo = false;
            string _repatriation = ""; bool _repatriationNo = false;
            string _hospitalinc = ""; bool _hospitalincNo = false;
            string _pregnancy = ""; bool _pregnancyNo = false;
            string _ocv = ""; bool _ocvNo = false;
            string _childguard = ""; bool _childguardNo = false;
            string _pl = ""; bool _plNo = false;
            string _lossbag = ""; bool _lossbagNo = false;
            string _bagdelay = ""; bool _bagdelayNo = false;
            string _tripcancel = ""; bool _tripcancelNo = false;
            string _tripcurtail = ""; bool _tripcurtailNo = false;
            string _traveldelay = ""; bool _traveldelayNo = false;
            string _travelconn = ""; bool _travelconnNo = false;
            string _traveloverbook = ""; bool _traveloverbookNo = false;
            string _money = ""; bool _moneyNo = false;
            string _traveldoc = ""; bool _traveldocNo = false;
            string _travelagency = ""; bool _travelagencyNo = false;
            string _homeprotect = ""; bool _homeprotectNo = false;
            string _carrent = ""; bool _carrentNo = false;
            string _hijack = ""; bool _hijackNo = false;
            string _kidnap = ""; bool _kidnapNo = false;
            string _phonecharge = ""; bool _phonechargeNo = false;
            string _policywordings = "";
            string docurl = "";

            if (qs_tiselected != "" && Cache["Mobile.TAResultsQuotes" + Session[General.TAId].ToString()] != null)
            {
                DataView dv = new DataView((DataTable)Cache["Mobile.TAResultsQuotes" + Session[General.TAId].ToString()]);

                string TAInsID = qs_tiselected; // Session["CarSelected"].ToString();

                //dv.RowFilter = " TAInsID in (" + TAInsID.Remove(TAInsID.Length - 1, 1) + ")";
                dv.RowFilter = " TAInsID in (" + TAInsID + ")";
                DataTable dtFiltered = dv.ToTable();

                if (dtFiltered.Rows.Count > 0)
                {
                    int rowCount = dtFiltered.Rows.Count;

                    for (int iRows = 0; iRows < rowCount; iRows++)
                    {
                        //string convertno = General.GetRefNumber(_cecarid);

                        _providercompanyid = dtFiltered.Rows[iRows]["ProviderCompanyId"].ToString();

                        string convertno = General.GetRefNumber(int.Parse(Session[General.TAId].ToString()));

                        if (_providercompanyid == "23")
                            _refno = "TIH" + convertno;
                        else if (_providercompanyid == "24")
                            _refno = "TIR" + convertno;
                        else if (_providercompanyid == "29")
                            _refno = "TIL" + convertno;
                        else if (_providercompanyid == "30")
                            _refno = "TIE" + convertno;
                        else if (_providercompanyid == "31")
                            _refno = "TIC" + convertno;
                        else if (_providercompanyid == "34")
                            _refno = "TICH" + convertno;
                        else if (_providercompanyid == "35")
                            _refno = "TIEQ" + convertno;
                        else if (_providercompanyid == "36")
                            _refno = "TIA" + convertno;
                        else if (_providercompanyid == "37")
                            _refno = "TI1C" + convertno;
                        else if (_providercompanyid == "38")
                            _refno = "TID" + convertno;

                        _companyName = dtFiltered.Rows[iRows]["insurername"].ToString();

                        _insurerimageurl = dtFiltered.Rows[iRows]["CompanyLogoServerUrl"].ToString();

                        if (dtFiltered.Rows[iRows]["CompanyLogoServerUrl"].ToString().Substring(0, 1) == "~")
                        {
                            _insurerimageurl = dtFiltered.Rows[iRows]["CompanyLogoServerUrl"].ToString().Remove(0, 1);
                        }

                        _package = "<strong>" + dtFiltered.Rows[iRows]["PlanName"].ToString() + "</strong>";


                        _annualprice = _annualprice + "<div style='color:#F00;font-size:20px;font-weight:bold;' >";
                        _annualprice = _annualprice + String.Format("{0:0,0.00}", Convert.ToSingle(dtFiltered.Rows[iRows]["annualpremium"].ToString()));
                        _annualprice = _annualprice + "</div>";

                        
                        //Personal Accident adult
                        if (Convert.ToInt32(dtFiltered.Rows[iRows]["DTPD_LessYr70"].ToString()) == 0)
                            _paadultNo = true;
                        else
                            _paadult = String.Format("${0:#,0}", Convert.ToInt32(dtFiltered.Rows[iRows]["DTPD_LessYr70"].ToString()));


                        //Personal Accident >70
                        if (Convert.ToInt32(dtFiltered.Rows[iRows]["DTPD_AboveYr70"].ToString()) == 0)
                            _paseniorNo = true;
                        else
                            _pasenior = String.Format("${0:#,0}", Convert.ToInt32(dtFiltered.Rows[iRows]["DTPD_AboveYr70"].ToString()));


                        //Double Indemnity adult
                        if (Convert.ToInt32(dtFiltered.Rows[iRows]["DIPC_LessYr70"].ToString()) == 0)
                            _diadultNo = true;
                        else
                            _diadult = String.Format("${0:#,0}", Convert.ToInt32(dtFiltered.Rows[iRows]["DIPC_LessYr70"].ToString()));


                        //Double Indemnity  >70
                        if (Convert.ToInt32(dtFiltered.Rows[iRows]["DIPC_AboveYr70"].ToString()) == 0)
                            _diseniorNo = true;
                        else
                            _disenior = String.Format("${0:#,0}", Convert.ToInt32(dtFiltered.Rows[iRows]["DIPC_AboveYr70"].ToString()));


                        //Medical Expense adult
                        if (Convert.ToInt32(dtFiltered.Rows[iRows]["MedExp_LessYr70"].ToString()) == 0)
                            _medexpadultNo = true;
                        else
                        {
                            _medexpadult = String.Format("${0:#,0}", Convert.ToInt32(dtFiltered.Rows[iRows]["MedExp_LessYr70"].ToString()));

                            if (_providercompanyid == "38")
                                _medexpadult = _medexpadult + "<br/>TCM: $300";
                            else if (_providercompanyid == "36")
                                _medexpadult = _medexpadult + "<br/>TCM: $750";
                        }

                        //Medical Expense senior
                        if (Convert.ToInt32(dtFiltered.Rows[iRows]["MedExp_AboveYr70"].ToString()) == 0)
                            _medexpseniorNo = true;
                        else
                        {
                            _medexpsenior = String.Format("${0:#,0}", Convert.ToInt32(dtFiltered.Rows[iRows]["MedExp_AboveYr70"].ToString()));

                            if (_providercompanyid == "38")
                                _medexpsenior = _medexpsenior + "<br/>TCM: $300";
                            else if (_providercompanyid == "36")
                                _medexpsenior = _medexpsenior + "<br/>TCM: $750";
                        }

                        //Emergency Medical Evacuation
                        if (_providercompanyid == "23")
                        {
                            _emergencymedevac = "<font color=Red>*as charged</font>";
                        }
                        else if (_providercompanyid == "24")
                        {
                            _emergencymedevac = "<font color=Red>Unlimited</font>";
                        }
                        else if (Convert.ToInt32(dtFiltered.Rows[iRows]["EmMedEval"].ToString()) == 0)
                        {
                            _emergencymedevacNo = true;
                        }
                        else
                        {
                            _emergencymedevac = String.Format("${0:#,0}", Convert.ToInt32(dtFiltered.Rows[iRows]["EmMedEval"].ToString()));

                            if (_providercompanyid == "38")
                                _emergencymedevac = _emergencymedevac + "<br/>(combined cover with Repatriation & Funeral Expense)";

                        }

                        //Repatriation & Funeral Expenses
                        if (dtFiltered.Rows[iRows]["info5"].ToString() == "True")
                        {
                            _repatriation = "<font color=Red>*as charged</font>";

                            if (_providercompanyid == "36" || _providercompanyid == "24")
                            {
                                _repatriation = "<font color=Red>Unlimited</font>";
                            }

                            if (_providercompanyid == "23")
                            {
                                _repatriation += "<br/>($30,000 for repatriation)";
                            }

                        }
                        else if (Convert.ToInt32(dtFiltered.Rows[iRows]["BCR"].ToString()) == 0)
                        {
                            _repatriationNo = true;
                        }
                        else
                        {
                            _repatriation = String.Format("${0:#,0}", Convert.ToInt32(dtFiltered.Rows[iRows]["BCR"].ToString()));

                            if (_providercompanyid == "38")
                            {
                                _repatriation = _repatriation + "<br/>(combined cover with Emergency Medical Evacuation)";
                            }
                        }

                        //Hospital Income
                        if (_providercompanyid == "24") //RSA
                        {
                            _hospitalinc = String.Format("{0:c0}", int.Parse(dtFiltered.Rows[iRows]["NInfo4"].ToString()));
                        }
                        else
                        {
                            float _fHospIncome = 0;
                            if (dtFiltered.Rows[iRows]["HospIncome"].ToString() != "")
                            {
                                _fHospIncome = Convert.ToSingle(dtFiltered.Rows[iRows]["HospIncome"].ToString());
                            }

                            if (_fHospIncome > 0.0f)
                            {
                                string _HospIncome = String.Format("{0:c0}", _fHospIncome);
                                _hospitalinc = _HospIncome + "/day <br/> max " + String.Format("{0:c0}", int.Parse(dtFiltered.Rows[iRows]["NInfo4"].ToString()));

                            }
                            else
                            {
                                _hospitalincNo = true;
                            }
                        }

                        //Pregnancy
                        float _fPregnancy = 0;
                        if (dtFiltered.Rows[iRows]["NInfo3"].ToString() != "")
                        {
                            _fPregnancy = Convert.ToSingle(dtFiltered.Rows[iRows]["NInfo3"].ToString());
                        }

                        if (_fPregnancy > 0.0f)
                        {
                            string _Pregnancy = String.Format("{0:c0}", _fPregnancy);

                            if (_providercompanyid == "38")
                            {
                                _pregnancy = "Covered under Medical Expenses (adult)";
                            }
                            else
                            {
                                _pregnancy = _Pregnancy;
                            }

                        }
                        else
                        {
                            _pregnancyNo = true;
                        }

                        //Overseas Compa Visit    
                        float _fCompaVisit = 0;
                        if (dtFiltered.Rows[iRows]["CompassVisit"].ToString() != "")
                        {
                            _fCompaVisit = Convert.ToSingle(dtFiltered.Rows[iRows]["CompassVisit"].ToString());
                        }

                        if (_fCompaVisit > 0.0f)
                        {
                            string _CompaVisit = String.Format("{0:c0}", _fCompaVisit);
                            _ocv = _CompaVisit;

                        }
                        else
                        {
                            _ocvNo = true;
                        }


                        //Child Guard

                        float _fChildGuard = 0;
                        if (dtFiltered.Rows[iRows]["ChildCare"].ToString() != "")
                        {
                            _fChildGuard = Convert.ToSingle(dtFiltered.Rows[iRows]["ChildCare"].ToString());
                        }

                        if (_fChildGuard > 0.0f)
                        {
                            string _ChildGuard = String.Format("{0:c0}", _fChildGuard);
                            _childguard = _ChildGuard;

                        }
                        else
                        {
                            _childguardNo = true;
                        }

                        //Personal Liability
                        float _fPL = 0;
                        if (dtFiltered.Rows[iRows]["PersonalLiability"].ToString() != "")
                        {
                            _fPL = Convert.ToSingle(dtFiltered.Rows[iRows]["PersonalLiability"].ToString());
                        }

                        if (_fPL > 0.0f)
                        {
                            string _PL = String.Format("{0:c0}", _fPL);
                            _pl = _PL;
                        }
                        else
                        {
                            _plNo = true;
                        }

                        //Loss Baggage & Personal Effects
                        float _fLossBaggage = 0;
                        if (dtFiltered.Rows[iRows]["BagPerEffect"].ToString() != "")
                        {
                            _fLossBaggage = Convert.ToSingle(dtFiltered.Rows[iRows]["BagPerEffect"].ToString());
                        }

                        if (_fLossBaggage > 0.0f)
                        {
                            string _LossBaggage = String.Format("{0:c0}", _fLossBaggage);
                            _lossbag = _LossBaggage;

                            if (_providercompanyid == "38")
                            {
                                _lossbag = _LossBaggage + "<br/>($500 per article/laptop/mobile phone or PDA)";
                            }

                            if (_providercompanyid == "24")
                            {
                                _lossbag = _LossBaggage + "<br/>$1,000 per item";
                            }
                        }
                        else
                        {
                            _lossbagNo = true;
                        }

                        //Overseas Baggage Delay
                        float _fOverseasBaggage = 0;
                        if (dtFiltered.Rows[iRows]["BagDelay"].ToString() != "")
                        {
                            _fOverseasBaggage = Convert.ToSingle(dtFiltered.Rows[iRows]["BagDelay"].ToString());
                        }

                        if (_fOverseasBaggage > 0.0f)
                        {
                            string _OverseasBaggage = String.Format("{0:c0}", _fOverseasBaggage) + "/" + dtFiltered.Rows[iRows]["Ninfo5"].ToString() + "-hour delay";
                            _OverseasBaggage += "<br/> max " + String.Format("{0:c0}", int.Parse(dtFiltered.Rows[iRows]["Ninfo6"].ToString()));
                            _bagdelay = _OverseasBaggage;

                            if (_providercompanyid == "38")
                            {
                                _bagdelay = String.Format("{0:c0}", int.Parse(dtFiltered.Rows[iRows]["Ninfo6"].ToString()));
                            }
                        }
                        else
                        {
                            _bagdelayNo = true;
                        }

                        //Trip Cancellation
                        float _fTripCancellation = 0;
                        if (dtFiltered.Rows[iRows]["DepositTripCancel"].ToString() != "")
                        {
                            _fTripCancellation = Convert.ToSingle(dtFiltered.Rows[iRows]["DepositTripCancel"].ToString());
                        }

                        if (_fTripCancellation > 0.0f)
                        {
                            string _TripCancellation = String.Format("{0:c0}", _fTripCancellation);
                            _tripcancel = _TripCancellation;

                        }
                        else
                        {
                            _tripcancelNo = true;
                        }


                        //Trip Curtailment
                        float _fTripCurtailment = 0;
                        if (dtFiltered.Rows[iRows]["Curtailment"].ToString() != "")
                        {
                            _fTripCurtailment = Convert.ToSingle(dtFiltered.Rows[iRows]["Curtailment"].ToString());
                        }

                        if (_fTripCurtailment > 0.0f)
                        {
                            string _TripCurtailment = String.Format("{0:c0}", _fTripCurtailment);
                            _tripcurtail = _TripCurtailment;

                            if (_providercompanyid == "38")
                            {
                                _tripcurtail = String.Format("{0:c0}", Convert.ToSingle(dtFiltered.Rows[iRows]["DepositTripCancel"].ToString()));
                            }
                        }
                        else
                        {
                            _tripcurtailNo = true;
                        }
                        //Overseas Travel Delay
                        float _fTravelDelay = 0;
                        if (dtFiltered.Rows[iRows]["TravelDelay"].ToString() != "")
                        {
                            _fTravelDelay = Convert.ToSingle(dtFiltered.Rows[iRows]["TravelDelay"].ToString());
                        }

                        if (_fTravelDelay > 0.0f)
                        {
                            if (_providercompanyid == "38")
                            {
                                string _TravelDelay = "$1,000 <br/>($100 per 6 hrs *)<br/>* $50 per 6 hrs for Jetstar and Tiger";
                                _traveldelay = _TravelDelay;

                            }
                            else
                            {
                                string _TravelDelay = String.Format("{0:c0}", _fTravelDelay) + "/" + dtFiltered.Rows[iRows]["Ninfo7"].ToString() + "-hour delay";
                                _TravelDelay += "<br/> max " + String.Format("{0:c0}", int.Parse(dtFiltered.Rows[iRows]["Ninfo8"].ToString()));
                                _traveldelay = _TravelDelay;
                            }

                        }
                        else
                        {
                            _traveldelayNo = true;
                        }


                        //Missed Travel Connection
                        float _fTravelConnection = 0;
                        if (dtFiltered.Rows[iRows]["MissTravelConnection"].ToString() != "")
                        {
                            _fTravelConnection = Convert.ToSingle(dtFiltered.Rows[iRows]["MissTravelConnection"].ToString());
                        }

                        if (_fTravelConnection > 0.0f)
                        {
                            string _TravelConnection = String.Format("{0:c0}", _fTravelConnection);
                            _travelconn = _TravelConnection;
                        }
                        else
                        {
                            _travelconnNo = true;
                        }

                        //Travel Overbooked
                        float _fTravelOverbooked = 0;
                        if (dtFiltered.Rows[iRows]["TravelOverBook"].ToString() != "")
                        {
                            _fTravelOverbooked = Convert.ToSingle(dtFiltered.Rows[iRows]["TravelOverBook"].ToString());
                        }

                        if (_fTravelOverbooked > 0.0f)
                        {
                            string _TravelOverbooked = String.Format("{0:c0}", _fTravelOverbooked);
                            _traveloverbook = _TravelOverbooked;
                        }
                        else
                        {
                            _traveloverbookNo = true;
                        }

                        //Loss of Personal Money
                        float _fLossMoney = 0;
                        if (dtFiltered.Rows[iRows]["PersonalMoney"].ToString() != "")
                        {
                            _fLossMoney = Convert.ToSingle(dtFiltered.Rows[iRows]["PersonalMoney"].ToString());
                        }

                        if (_fLossMoney > 0.0f)
                        {
                            string _LossMoney = String.Format("{0:c0}", _fLossMoney);
                            _money = _LossMoney;
                        }
                        else
                        {
                            _moneyNo = true;
                        }

                        //Loss of Travel Documents
                        float _fLossDocument = 0;
                        if (dtFiltered.Rows[iRows]["TravelDoc"].ToString() != "")
                        {
                            _fLossDocument = Convert.ToSingle(dtFiltered.Rows[iRows]["TravelDoc"].ToString());
                        }

                        if (_fLossDocument > 0.0f)
                        {
                            string _LossDocument = String.Format("{0:c0}", _fLossDocument);
                            _traveldoc = _LossDocument;
                        }
                        else
                        {
                            _traveldocNo = true;
                        }

                        //Closure of Travel Agency
                        float _fClosure = 0;
                        if (dtFiltered.Rows[iRows]["Info3"].ToString() != "")
                        {
                            _fClosure = Convert.ToSingle(dtFiltered.Rows[iRows]["Info3"].ToString());
                        }

                        if (_fClosure > 0.0f)
                        {
                            string _Closure = String.Format("{0:c0}", _fClosure);
                            _travelagency = _Closure;
                        }
                        else
                        {
                            _travelagencyNo = true;
                        }

                        //Home Contents
                        float _fHomeContent = 0;
                        if (dtFiltered.Rows[iRows]["FBHCP"].ToString() != "")
                        {
                            _fHomeContent = Convert.ToSingle(dtFiltered.Rows[iRows]["FBHCP"].ToString());
                        }

                        if (_fHomeContent > 0.0f)
                        {
                            string _HomeContent = String.Format("{0:c0}", _fHomeContent);
                            _homeprotect = _HomeContent;

                            if (_providercompanyid == "23")
                            {
                                if (Session["TripType"].ToString() == "A")
                                {
                                    _homeprotect = "Optional";
                                }
                            }
                        }
                        else
                        {
                            _homeprotectNo = true;
                        }

                        //Rental Vehicle
                        float _fRentalVehicle = 0;
                        if (dtFiltered.Rows[iRows]["ACRR"].ToString() != "")
                        {
                            _fRentalVehicle = Convert.ToSingle(dtFiltered.Rows[iRows]["ACRR"].ToString());
                        }

                        if (_fRentalVehicle > 0.0f)
                        {
                            string _RentalVehicle = String.Format("{0:c0}", _fRentalVehicle);
                            _carrent = _RentalVehicle;

                        }
                        else
                        {
                            _carrentNo = true;
                        }

                        //Hijack
                        float _fHijack = 0;
                        if (dtFiltered.Rows[iRows]["Terrorism"].ToString() != "")
                        {
                            _fHijack = Convert.ToSingle(dtFiltered.Rows[iRows]["Terrorism"].ToString());
                        }

                        if (_fHijack > 0.0f)
                        {
                            string _Hijack = String.Format("{0:c0}", _fHijack) + "/" + dtFiltered.Rows[iRows]["Info1"].ToString() + "-hour";
                            _Hijack += "<br/> max " + String.Format("{0:c0}", int.Parse(dtFiltered.Rows[iRows]["Info2"].ToString()));
                            _hijack = _Hijack;
                        }
                        else
                        {
                            _hijackNo = true;
                        }

                        //Kidnap / Hostage
                        float _fKidnap = 0;
                        if (dtFiltered.Rows[iRows]["KidnapHostage"].ToString() != "")
                        {
                            _fKidnap = Convert.ToSingle(dtFiltered.Rows[iRows]["KidnapHostage"].ToString());
                        }

                        if (_fKidnap > 0.0f)
                        {
                            string _Kidnap = String.Format("{0:c0}", _fKidnap);
                            _kidnap = _Kidnap;

                        }
                        else
                        {
                            _kidnapNo = true;
                        }

                        //Emergency Tel Charges
                        float _fTelCharge = 0;
                        if (dtFiltered.Rows[iRows]["EmTelCharge"].ToString() != "")
                        {
                            _fTelCharge = Convert.ToSingle(dtFiltered.Rows[iRows]["EmTelCharge"].ToString());
                        }

                        if (dtFiltered.Rows[iRows]["Info6"].ToString() != "" && dtFiltered.Rows[iRows]["Info6"].ToString() == "True")
                        {
                            _phonecharge = "<font color='red'>*actual cost</font>";
                        }
                        else
                        {
                            if (_fTelCharge > 0.0f)
                            {
                                string _TelCharge = String.Format("{0:c0}", _fTelCharge);
                                _phonecharge = _TelCharge;
                            }
                            else
                            {
                                _phonechargeNo = true;
                            }
                        }

                        //policy
                        string _policyId = dtFiltered.Rows[iRows]["NInfo1"].ToString();

                        ProviderPolicyDocument _policydoc = new ProviderPolicyDocument();
                        ProviderPolicyDocumentDB _policydocdb = new ProviderPolicyDocumentDB();

                        _policydoc = _policydocdb.GetProviderPolicyDocument(Convert.ToInt64(_policyId));

                        docurl = "http://www.comparexpress.com" + _policydoc.UploadPath.Remove(0, 1);
                        _policywordings = docurl;
                       // hlnkPolicyDoc.ImageUrl = "http://www.comparexpress.com/images/icon/pdf.png";
                        
                    }
                }

            }
            string _emailList = "", _title = "";
            System.Text.StringBuilder _message = new System.Text.StringBuilder();
            _emailList = Session[CE.Global.General.TAEmail].ToString();
            //_emailList += ";team@comparexpress.com";
            //string _currentDomainUrl = "http://" + HttpContext.Current.Request.Url.Host.ToString() + "/";
            string _currentDomainUrl = "http://www.comparexpress.com/";
            _title = "";

            _title = "CompareXpress.com (Ref No : " + _refno + ")";

            _message.Append("<table cellpadding='0' cellspacing='0' border='0' width='270' style='font-family:Arial, Helvetica, sans-serif; font-size:12px; margin:0 auto;'>");
            _message.Append("<tr><td style='border-bottom:1px solid #ccc;' align='center'><img src='http://www.comparexpress.com/images/nav/logo_comparexpress.png' alt='' height='78' /><br/><br/>");
            _message.Append("Thank you for choosing CompareXpress.com <br/><strong>Here is your Quote Details </strong><br /><br/></td></tr>");

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><br /><table cellspacing='0' cellpadding='2' width='100%' border='0'>");

            _message.Append("<tr><td valign='top'>Quote Ref Number</td>");
            _message.Append("<td valign='top'><strong><u>" + _refno + "</u></strong></td></tr>");

            _message.Append("<tr><td valign='top'>Trip Type</td>");
            _message.Append("<td valign='top'><strong>" + _triptype + "</strong></td></tr>");

            _message.Append("<tr><td valign='top'>Type of Policy</td>");
            _message.Append("<td valign='top'><strong>" + _policy + "</strong></td></tr>");

            _message.Append("<tr><td valign='top'>Coverage</td>");
            _message.Append("<td valign='top'><strong>" + _coverage + "</strong></td></tr>");

            _message.Append("<tr><td valign='top'>Destionation</td>");
            _message.Append("<td valign='top'><strong>" + _destination + "%</strong></td></tr>");

            _message.Append("<tr><td valign='top'>Travel Date</td>");
            _message.Append("<td valign='top'><strong>" + _traveldate + "</strong></td></tr>");

            _message.Append("<tr><td valign='top'>No. of Traveller/s</td>");
            _message.Append("<td valign='top'><strong>" + _travellers + "</strong></td></tr>");

            _message.Append("<tr><td valign='top'>Quote Date</td>");
            _message.Append("<td valign='top'><strong>" + CE.Global.General.GetUTCDateTime().ToString("dd/MMM/yyyy") + "</strong></td></tr>");

            _message.Append("</table><br /></td></tr><tr><td width='300'><br />");

            _message.Append("<table width='100%' border='0' cellpadding='5' cellspacing='0'  class='table_details'>");

            _message.Append("<tr><td width='45%'></td>");
            _message.Append("<td width='55%' align='center' style='background:#e0e0e0; border-bottom:white 1px dashed;'>");
            _message.Append("<img src='" + _currentDomainUrl + _insurerimageurl + "' width='120px' /></td></tr>");

            _message.Append("<tr><td><strong>Insurer</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5; color:black;' ><strong>" + _companyName + "</strong></td></tr>");

            _message.Append("<tr><td></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>" + _package + "</td></tr>");

            _message.Append("<tr><td align='left' style='background:#d5d5d5' ><strong>Annual Premium</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5; color:black; font-size:16px;'><strong>" + _annualprice + "</strong></td></tr>");

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Personal Accident (adult)</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5' >");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_paadultNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_paadult + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Personal Accident (senior)</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5' >");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_paseniorNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_pasenior + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Double Indemnity (adult)</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_diadultNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_diadult + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Double Indemnity (senior)</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_diseniorNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_disenior + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Medical Expense (adult)</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_medexpadultNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_medexpadult + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Medical Expense (senior)</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_medexpseniorNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_medexpsenior + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Emergency Medical Evacuation</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_emergencymedevacNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_emergencymedevac + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Repatriation & Funeral Expenses</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_repatriationNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_repatriation + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Hospital Income</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_hospitalincNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_hospitalinc + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Pregnancy-related Illness</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_pregnancyNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_pregnancy + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Overseas Compassionate Visit</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_ocvNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_ocv + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Child Guard</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_childguardNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_childguard + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Personal Liability</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_plNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_pl + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Loss Baggage & Personal Effects</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_lossbagNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_lossbag + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Overseas Baggage Delay</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_bagdelayNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_bagdelay + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Trip Cancellation</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_tripcancelNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_tripcancel + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Trip Curtailment</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_tripcurtailNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_tripcurtail + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Overseas Travel Delay</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_traveldelayNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_traveldelay + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Missed Travel Connection</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_travelconnNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_travelconn + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Travel Overbooked</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_traveloverbookNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_traveloverbook + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Loss of Personal Money</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_moneyNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_money + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Loss of Travel Documents</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_traveldocNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_traveldoc + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Closure of Travel Agency</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_travelagencyNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_travelagency + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Home Contents Protection</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_homeprotectNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_homeprotect + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Rental Vehicle Excess</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_carrentNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_carrent + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Hijack</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_hijackNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_hijack + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Kidnap/Hostage</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_kidnapNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_kidnap + "</td></tr>");
            }

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>Emergency Telephone Charges</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>");

            if (_providercompanyid == "34")
                _message.Append("<a href='http://www.comparexpress.com/policy_docs/ChinaTaiping/Coverage.pdf' target='_blank' ><img src='http://www.comparexpress.com/images/icon/pdf.png' /></a></td></tr>");
            else
            {
                if (_phonechargeNo)
                    _message.Append("<img src='http://www.comparexpress.com/images/icon/X.png' /></td></tr>");
                else
                    _message.Append(_phonecharge + "</td></tr>");
            }

            string viewpolicywordings = "<a href='" + docurl + "' ><img src='http://www.comparexpress.com/images/icon/pdf.png'  alt='policy wordings' width='23' alt='NA' border='0'/></a>";

            _message.Append("<tr><td style='border-bottom:1px solid #ccc;'><strong>View Policy Wordings</strong></td>");
            _message.Append("<td align='center' style='background:#d5d5d5;'>" + viewpolicywordings + "</td></tr>");

            _message.Append("</table><br /><br />");

            _message.Append("<strong>Important Notes</strong><br />");
            _message.Append("• The amounts listed in the benefits table are the maximum coverage payable for each benefit.<br />");
            _message.Append("• Coverage intended for overseas traveling and not in Singapore. Insured person must be Singaporean or Singapore Permanent Resident only. <br />");
            _message.Append("• Information displayed here is a summary. Please read the actual policy wordings for details of coverage. <br />");
            _message.Append("</td></tr><tr><td id='email_footer'></td>");
            _message.Append("</tr></table><br /><br /><hr />This Quote is subject to the insurer's final confirmation and coverage is only effective when the insurer has accepted the risk.<br /><br />");
            _message.Append("<i>This is a computer-generated email. Please do not reply to this email.</i><hr />");

            MyMailManager.SendCRMMessage(_emailList, _title, _message.ToString());
            Response.Redirect("../email-confirm.aspx?type=email&resultid=" + taresultid);
        }
        else
        {
            Response.Redirect("travel-quote.aspx");
        }
    }

    protected string GetAreaName(Int64 areaid)
    {
        string Area = "";

        AreaInfo _areainfo = new AreaInfo();
        AreaInfoDB _areainfodb = new AreaInfoDB();

        _areainfo = _areainfodb.GetAreaInfo(areaid);

        Area = _areainfo.Description;

        return Area;

    }

    protected string GetCountryName(Int64 countryid)
    {
        string Country = "";

        CountryInfo _countryinfo = new CountryInfo();
        CountryInfoDB _countryinfodb = new CountryInfoDB();

        _countryinfo = _countryinfodb.GetCountryInfo(countryid);

        Country = _countryinfo.Description;

        return Country;

    }

    protected string GetPolicy(string covertype)
    {
        string policy = "family";

        if (covertype == "IND")
        {
            policy = "Individual";
        }
        else if (covertype == "INS")
        {
            policy = "Individual + Spouse";
        }
        else if (covertype == "INC")
        {
            policy = "Individual + Child";
        }
        else if (covertype == "FML")
        {
            policy = "Family";
        }

        return policy;
    }

    protected string GetCoverage(string coverage)
    {
        string cover = "Single Trip";

        if (coverage == "A")
            cover = "Annual Multi-trip";

        return cover;
    }

    private void LogUserSelectHistory(string CoverType, Int64 ResultId, Int64 CompanyId)
    {
        UserSelectHistoryDB _userselectdb = new UserSelectHistoryDB();
        if (CoverType.ToLower() == "ind")
        {
            _userselectdb.LogUserSelectHistory("TA", Request.Browser.Type, Request.UserHostAddress, "TAIND", ResultId, CompanyId);
        }
        else if (CoverType.ToLower() == "ins")
        {
            _userselectdb.LogUserSelectHistory("TA", Request.Browser.Type, Request.UserHostAddress, "TAINDSP", ResultId, CompanyId);
        }
        else
        {
            _userselectdb.LogUserSelectHistory("TA", Request.Browser.Type, Request.UserHostAddress, "TAFML", ResultId, CompanyId);
        }

    }

    private void TAUserOptionLog(bool isBuyNow, bool isCallMe, bool isEmailMe)
    {
        TAUserOption tauseroption = new TAUserOption();
        TAUserOptionDB tauseroptiondb = new TAUserOptionDB();

        tauseroption.TAUserOptionId = 0;
        tauseroption.TAId = Convert.ToInt64(Session[General.TAId].ToString());
        tauseroption.IsBuyNow = isBuyNow;
        tauseroption.IsCallMe = isCallMe;
        tauseroption.IsEmailMe = isEmailMe;
        tauseroption.IsEmailThis = false;
        tauseroption.RecipientName = "";
        tauseroption.RecipientEmailAddress = "";
        tauseroption.ViewedDetailId = 0;
        tauseroption.RefCEUserId = 0;

        if (Session[General.UserId] != null)
        {
            if (Session[General.UserId].ToString() != "")
                tauseroption.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
        }

        tauseroptiondb.Insert(tauseroption);
    }

    protected void BuyNow()
    {
        Session["TAFromSummary"] = "1";
        TAUserOptionLog(true, false, false);

        Int64 _UserId = 0;
        if (Session[General.UserId] != null)
        {
            _UserId = Convert.ToInt64(Session[General.UserId].ToString());
        }

        string CoverType = inputPlanType.Value.Trim().ToString();
        string PlanName = inputPlanName.Value.Trim().ToString();
        string ProviderID = inputProviderId.Value.Trim().ToString();

        Int64 TAId = Convert.ToInt64(inputTAId.Value.Trim().ToString());
        Int64 _resultId = Convert.ToInt64(inputResultId.Value.ToString());

        float TotalPremium = 0;
        TotalPremium = float.Parse(inputPremium.Value.Trim().ToString());

        if (Session[General.TAId] != null)
            TAId = Convert.ToInt64(Session[General.TAId]);

        LogUserSelectHistory(CoverType, _resultId, Convert.ToInt64(ProviderID));

        //update total premium field
        TAApplicantSearchDB _taapplicantsearchdb = new TAApplicantSearchDB();
        TAApplicantSearchDB _taapplicantsearchdbBuy = new TAApplicantSearchDB();

        Int64 UpdatedId = _taapplicantsearchdbBuy.UpdatePremium(TAId, TotalPremium, _resultId, Convert.ToInt64(ProviderID), PlanName);

        //Session[General.TAResultId] = _resultId;

        //if (_UserId == 0)
        //{
        //    _taapplicantsearchdb.UpdateProfileDetails(TAId, txtFullName.Text, txtMobileNo.GetPhoneNo(), txtEmail.Text);
        //}

    }
}
